package com.elong.android.specialhouse.account;

import android.content.Context;

import com.elong.android.specialhouse.utils.PreferencesHelper;
import com.elong.myelong.usermanager.User;

import java.io.Serializable;

/**
 * @author cheng.wang
 * @date 2015/8/28
 */
public class Account implements Serializable {
    private static final long serialVersionUID = 1L;
    private static Account instance;
    private static PreferencesHelper mPrefHelper;

    private Account() {
    }

    public static void init(Context con) {
        if (con != null) {
            User.init(con);
            mPrefHelper = new PreferencesHelper(con);
        }
        return;
    }

    public static Account getInstance() {
        if (instance == null) {
            instance = new Account();
        }
        return instance;
    }

    private void reset() {
        if (mPrefHelper != null) {
            String phoneNo = getPhoneNumber();
            mPrefHelper.clear();
            setPhoneNumber(phoneNo);
        }
        User.getInstance().setName((String) null);
        User.getInstance().setCardNo(0L);
        User.getInstance().setGender((String) null);
        User.getInstance().setEmail((String) null);
//            User.getInstance().setPassword((String) null);
        User.getInstance().setCreditCount(0);
        User.getInstance().setUserCouponValue(0);
        User.getInstance().setLogin(false);
        this.refreshSessionToken("");
    }

    public void logout() {
        if (mPrefHelper != null) {
            setLogin(false);
            reset();
        }
    }

    /**
     * 这些用 mPrefHelper保存的信息是公寓独有的
     *
     * @return
     */
    public String getUserId() {
        return mPrefHelper.getString("userId");
    }

    public void setUserId(String userId) {
        mPrefHelper.saveString("userId", userId);
    }
    public String getRealName() {
        return mPrefHelper.getString("realName");
    }

    public void setRealName(String realName) {
        mPrefHelper.saveString("realName", realName);
    }
    public String getIdCardNumber() {
        return mPrefHelper.getString("idCardNumber");
    }

    public void setIdCardNumber(String idCardNumber) {
        mPrefHelper.saveString("idCardNumber", idCardNumber);
    }

    public String getAvatar() {
        return mPrefHelper.getString("avatar");
    }

    public void setAvatar(String avatar) {
        mPrefHelper.saveString("avatar", avatar);
    }

    public String getIdentityPass() {
        return mPrefHelper.getString("identityPass");
    }

    public void setIdentityPass(String identityPass) {
        mPrefHelper.saveString("identityPass", identityPass);
    }

    public String getIdentityPassDecription() {
        return mPrefHelper.getString("identityPass");
    }

    public void setIdentityPassDecription(String identityPassDecription) {
        mPrefHelper.saveString("identityPassDecription", identityPassDecription);
    }

    public boolean isCustomer() {
        return mPrefHelper.getBoolean("isCustomer", true);
    }

    public void setIsCustomer(boolean isCustomer) {
        mPrefHelper.saveBoolean("isCustomer", isCustomer);
    }
    public boolean currentIsCustomer() {
        return mPrefHelper.getBoolean("currentIsCustomer", true);
    }

    public void setCurrentIsCustomer(boolean currentIsCustomer) {
        mPrefHelper.saveBoolean("currentIsCustomer", currentIsCustomer);
    }

    public boolean isLandlord() {
        return mPrefHelper.getBoolean("isLandlord");
    }

    public void setIsLandlord(boolean isLandlord) {
        mPrefHelper.saveBoolean("isLandlord", isLandlord);
    }

    public String getPhoneNumber() {
        return mPrefHelper.getString("phoneNumber");
    }

    public void setPhoneNumber(String phoneNumber) {
        mPrefHelper.saveString("phoneNumber",phoneNumber);
        User.getInstance().setPhoneNo(phoneNumber);
    }


    public String getPassword() {
        return User.getInstance().getPassword();
    }

    public void setPassword(String password) {
        User.getInstance().setPassword(password);
    }

    public String getAccessToken() {
        return User.getInstance().getSessionToken();
    }


    public String getNickName() {
        return User.getInstance().getName();
    }

    public void setNickName(String nickName) {
        User.getInstance().setName(nickName);
    }


    public long getCardNo() {
        return User.getInstance().getCardNo();
    }


    public String getGender() {
        return User.getInstance().getGender();
    }

    public String getEmail() {
        return User.getInstance().getEmail();
    }


    public int getCreditCount() {
        return User.getInstance().getCreditCount();
    }

    public int getUserLever() {
        return User.getInstance().getCreditCount();
    }

    public int getUserCouponValue() {
        return User.getInstance().getUserCouponValue();
    }

    public boolean isLogin() {
        return User.getInstance().isLogin();
    }

    public boolean isHasSetPwdForCashAccount() {
        return User.getInstance().isHasSetPwdForCashAccount();
    }

    public void refreshSessionToken(String token) {
        User.getInstance().refreshSessionToken(token);
    }


    public void setLogin(boolean isLogin) {
        User.getInstance().setLogin(isLogin);
    }

    public void setCardNo(long cardNo) {
        User.getInstance().setCardNo(cardNo);
    }

    public void setCreditCount(int user_count) {
        User.getInstance().setCreditCount(user_count);
    }

    public void setEmail(String email) {
        User.getInstance().setEmail(email);
    }

    public void setGender(String gender) {
        User.getInstance().setGender(gender);
    }

    public void setHasSetPwdForCashAccount(boolean hasSetPwdForCashAccount) {
        User.getInstance().setHasSetPwdForCashAccount(hasSetPwdForCashAccount);
    }

    public void setUserCouponValue(int coupon) {
        User.getInstance().setUserCouponValue(coupon);
    }

    public void setUserLever(int userLever) {
        User.getInstance().setUserLever(userLever);
    }


    public boolean isDragonVIP() {
        return User.getInstance().isDragonVIP();
    }

    public void setGiftCardAmount(double giftCardAmount) {
        User.getInstance().setGiftCardAmount(giftCardAmount);
    }

    public void setAutoLogin(boolean isAutoLogin) {
        User.getInstance().setAutoLogin(isAutoLogin);
    }

    public boolean isAutoLogin() {
        return User.getInstance().isAutoLogin();
    }

    public void setSex (String sex) {
    	mPrefHelper.saveString("user_sex", sex);
    }

    public String getSex () {
    	return mPrefHelper.getString("user_sex");
    }

    public void setBirthYear (String birth_year) {
    	mPrefHelper.saveString("birth_year", birth_year);
    }

    public String getBirthYear () {
    	return mPrefHelper.getString("birth_year");
    }

    public void setBirthMonth (String birth_month) {
    	mPrefHelper.saveString("birth_month", birth_month);
    }

    public String getBirthMonth () {
    	return mPrefHelper.getString("birth_month");
    }

    public void setBirthDay (String birth_day) {
    	mPrefHelper.saveString("birth_day", birth_day);
    }

    public String getBirthDay () {
    	return mPrefHelper.getString("birth_day");
    }

    public void setPersonnalProfile (String person_profile) {
    	mPrefHelper.saveString("personnal_profile", person_profile);
    }

    public String getPersonnalProfile () {
    	return mPrefHelper.getString("personnal_profile");
    }
}
